package nl.mayisal.metadata.factories;

import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;

import nl.mayisal.metadata.columns.AbstractColumnStructure;
import nl.mayisal.metadata.columns.NumberColumnStructure;
import nl.mayisal.metadata.columns.SimpleColumnStructure;

public class ColumnStructureFactory {
	private ColumnStructureFactory() {}
	
	public static AbstractColumnStructure<?> createColumn(String name, int type, int length, int digits, int radix, String defaultValueExpression) {
		switch(type) {
			case Types.DATE:
				return new SimpleColumnStructure<Date>(type,name,length, defaultValueExpression);
			case Types.TIME:
				return new SimpleColumnStructure<Time>(type,name,length, defaultValueExpression);
			case Types.TIMESTAMP:
				return new SimpleColumnStructure<Timestamp>(type,name,length, defaultValueExpression);
			case Types.CHAR:
			case Types.VARCHAR: 
			case Types.LONGVARCHAR:
			case Types.LONGNVARCHAR:
			case Types.NCHAR:
			case Types.NVARCHAR:	
				return new SimpleColumnStructure<String>(type, name, length, defaultValueExpression);
			case Types.INTEGER:
			case Types.TINYINT:
			case Types.SMALLINT:
			case Types.BIGINT:
				return new NumberColumnStructure<Integer>(type,name,length,0,radix,defaultValueExpression);
			case Types.DECIMAL:
			case Types.DOUBLE:
			case Types.NUMERIC:
				return new NumberColumnStructure<Double>(type,name,length,digits,radix,defaultValueExpression);
			case Types.FLOAT:
				return new NumberColumnStructure<Float>(type,name,length,digits,radix,defaultValueExpression);
			case Types.BOOLEAN:
			case Types.BIT:
				return new SimpleColumnStructure<Boolean>(type,name,length,defaultValueExpression);
			case Types.LONGVARBINARY:
			case Types.VARBINARY:
			case Types.BINARY:
				return new SimpleColumnStructure<Object>(type,name,length,defaultValueExpression);
			// Following types should still get a implementation	
			case Types.ROWID:
			case Types.NULL:
			case Types.REAL:
			case Types.DATALINK:
			case Types.OTHER:
			case Types.JAVA_OBJECT:
			case Types.DISTINCT:
			case Types.STRUCT:
			case Types.ARRAY:
			case Types.BLOB:
			case Types.CLOB:
			case Types.REF:
			case Types.SQLXML:
			case Types.NCLOB:
			default:
				throw new IllegalArgumentException("ColumnType "+type+" not supported");
		}
	}
	
	
}
